//
//  UIBarButtonItem+Extension.swift
//  MySina
//
//  Created by imppppp on 16/5/20.
//  Copyright © 2016年 IMP. All rights reserved.
//

import UIKit

private let ItemNormalColor = UIColor(red: 80/255, green: 80/255, blue: 80/255, alpha: 1)
private let ItemHighlightedColor = UIColor.orangeColor()

extension UIBarButtonItem {
    
//    rightBtn.setImage(UIImage(named: "navigationbar_pop"), forState: .Normal)
//    rightBtn.setImage(UIImage(named: "navigationbar_pop_highlighted"), forState: .Highlighted)
//    rightBtn.addTarget(self, action: #selector(rightBtnClick), forControlEvents: .TouchUpInside)

//    根据给定参数判断是否创建对象，而不像指定构造函数那样必须要实例化一个对象出来
//    在实际开发中，可以对已有类的构造函数进行扩展，利用便利构造函数，简化对象的创建
    convenience init(imageName: String, title:String? = nil, target: AnyObject, action: Selector) {
        
        self.init()
        
        let btn = UIButton()
        
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(ItemNormalColor, forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        btn.sizeToFit()
        
        self.customView = btn
        
    }
}
